package com.acidsweet.zerolrucachesample;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jin on 16/10/20.
 */

public class MainActivity extends Activity implements AdapterView.OnItemClickListener{
    public static final String[] mCacheModes={"MemoryLruCache","DiskLruCache","UnionLruCache"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView listView=(ListView)findViewById(R.id.main_listview);
        listView.setAdapter(new SimpleAdapter(MainActivity.this,getData(),android.R.layout.simple_list_item_1,new String[]{"title"},new int[]{android.R.id.text1}));
        listView.setOnItemClickListener(this);
    }
    private List<Map<String, String>> getData()
    {
        List<Map<String,String>> list=new ArrayList<>();
        for (String i:mCacheModes)
        {
            Map<String,String> map=new HashMap<>();
            map.put("title",i);
            list.add(map);
        }
        return list;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        moveToDetail(position);
    }
    private void moveToDetail(int mode)
    {
        Intent in=new Intent(MainActivity.this,DetailActivity.class);
        in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        in.putExtra("mode",mCacheModes[mode]);
        startActivity(in);
    }
}
